<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2018/4/3
  Time: 20:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>执行更改</title>
</head>
<body>
<%

    if (session.getAttribute("isLogin")==null){
        response.sendRedirect("login.jsp");
    }

    request.setCharacterEncoding("UTF-8");
    String id=request.getParameter("id");
    String username=request.getParameter("username");
    String password=request.getParameter("password");

    //链接数据库
    Connection connection=null;
    PreparedStatement preparedStatement=null;
//    ResultSet resultSet=null;


    //注册数据库
    Class.forName("com.mysql.jdbc.Driver");

    //获取链接
    connection= DriverManager.getConnection("jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone=UTC",
            "root",
            "123456"
            );

    //数据库指令
    String sql="update t_users set id=?, username=?, password=? where id=?";



    //发送sql语句
    preparedStatement=connection.prepareStatement(sql);

    //插入到具体地方
    preparedStatement.setString(1,id);
    preparedStatement.setString(2,username);
    preparedStatement.setString(3,password);
    preparedStatement.setInt(4,Integer.parseInt(id)); //?为什么要加这个，是什么意思
//    int result=preparedStatement.executeUpdate();
//    String msg="更新失败！";
//    if (result==1){
//        msg="更新成功！";
//    }


    preparedStatement.executeUpdate();

    connection.close();
    preparedStatement.close();
%>
</body>
</html>
